﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Pure.Token;
using Pure.Token.Model;

namespace Pure.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        /// <summary>
        /// 测试接口,用于验证权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetStu")]

        public string GetStu(string id)
        {
            return id;
        }

        /// <summary>
        ///  测试接口(获取jwt),生产环境需继承自业务系统
        /// </summary>
        /// <param name="id">用户id</param>
        /// <param name="Uname">姓名</param>
        /// <param name="Sub">身份</param>
        /// <returns></returns>
        [HttpGet, Route("Set")]
        [AllowAnonymous]
        public string Set(int id, string Uname, string Sub)
        {
            var model = new TokenModel()
            {
                Uid = id,
                Uname = Uname,
                Sub = Sub
            };
            var encodedJwt = RayPIToken.IssueJWT(model, TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));
            return $"{encodedJwt}";
        }
    }
}